# 文件处理
# 处理txt
# class Readfiles():
#     def read1(self, f, a):
#         # f=r"D:\work\codings\python\2501\post_2501\files\新建 文本文档.txt"
#         ff = open(f, 'r', encoding="utf-8")
#         print(ff.read())
# if __name__ == '__main__':
#     # f = r"D:\work\codings\python\2501\post_2501\files\新建 文本文档.txt"
#     reading = Readfiles()
#     reading.read1()
# 二进制查看图片
# class Readfiles():
#     def read1(self, f, a):
#         # f=r"D:\work\codings\python\2501\post_2501\files\新建 文本文档.txt"
#         ff = open(f, a)
#         print(ff.read())
# if __name__ == '__main__':
#     f = r"D:\work\codings\python\2501\post_2501\data\微信图片_20250228161903.jpg"
#     reading = Readfiles()
#     reading.read1(f, "r+b")
import openpyxl
from openpyxl.workbook import Workbook
from openpyxl.worksheet.worksheet import Worksheet


class Readfiles():
    #     def read1(self, f, b, UTF=False):
    #         if UTF:
    # #由于打开文件后，总是忘记关闭，很容易造成文件丢失，为了解决这个问题
    # #采用with代码块的方式，一旦离开with代码块，文件自动关闭
    #             with open(f, b, encoding='utf-8') as ff:
    #                 w=ff.read()
    #         else:
    #             with open(f, b) as ff:
    #                 w=ff.read()
    #         print(w)
    #         return w
    #
    #     def Write1(self, f, a, s, UTF=False):
    #         if UTF:
    #             with open(f, a, encoding='utf-8') as ff:
    #                 w=ff.write(s)
    #             print(w)
    #         else:
    #             with open(f, a) as ff:
    #                 w=ff.write(s)
    #         print(w)
    #         return w
    # ecxel读
    # def excelRead(self, f):
    #     wb: Workbook = openpyxl.load_workbook(f)
    #     ws: Worksheet = wb["Sheet1"]
    #     w = ws.iter_rows(2, 3, 2, 3, values_only=True)
    #     l = [i for i in w]
    #     print(l)
    #     return l

    # excel写
    # def excelWrite(self, f):
    #     wb: Workbook = openpyxl.Workbook(f)
    #     ws: Worksheet = wb.create_sheet("whsst")
    #
    #     w = ws.iter_rows(2, 3, 2, 3, values_only=True)
    #     l = [i for i in w]
    #     print(l)
    #     return l
    def excelRead1(self, f,sname,minr,maxr,minc,maxc):
        wb: Workbook = openpyxl.load_workbook(f)
        ws: Worksheet = wb[sname]
        w = ws.iter_rows(minr,maxr,minc,maxc, values_only=True)
        l = [i for i in w]
        print(l)
        return l

if __name__ == '__main__':
    # f = r"D:\work\codings\python\2501\post_2501\data\微信图片_20250228161903.jpg"
    # f = r"D:\work\codings\python\2501\post_2501\files\新建 文本文档.txt"
    # Readfiles().Write1(f, "r+b")

    # Readfiles().Write1(f, "a", "hello,解决python", True)
    # Readfiles().read1(f, "r+b", False)
    # rd= Readfiles().read1(f, "r+b", False)
    # Readfiles().Write1(r"D:\work\codings\python\2501\post_2501\data\i.jpg","a+b",rd,False)
    q = Readfiles()
    # q.excelRead(r"D:\work\codings\python\2501\post_2501\data\值日.xlsx")
    f=r'D:\work\codings\python\2501\post_2501\files\yunSuanData.xlsx'
    q.excelRead1(f,"sum",2,55,2,5)
